/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ManagedBeans;

import Beans.Message;
import dao.MessageDao;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

/**

 @author Marie-Claude
 */
@ManagedBean(name = "messageManager")
@RequestScoped
public class MessageManager implements Serializable {

  private int selectedMessageId;
  private String selectedUsername;
  private int id;
  private List<Message> lstMessages;

  @ManagedProperty(value = "#{userManager}")
  private UserManager mbUser;

  /**
   Creates a new instance of MessageManager
   */
  public MessageManager() {

  }

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public List<Message> getLstMessages() {
    return lstMessages;
  }

  public void setLstMessages(List<Message> lstMessages) {
    this.lstMessages = lstMessages;
  }

  public int getSelectedMessageId() {
    return selectedMessageId;
  }

  public void setSelectedMessageId(int selectedMessageId) {
    this.selectedMessageId = selectedMessageId;
  }

  public UserManager getMbUser() {
    return mbUser;
  }

  public void setMbUser(UserManager mbUser) {
    this.mbUser = mbUser;
  }

  public String getSelectedUsername() {
    return selectedUsername;
  }

  public void setSelectedUsername(String selectedUsername) {
    this.selectedUsername = selectedUsername;
  }

  @PostConstruct
  public void init() {
    lstMessages = MessageDao.getListMessageById(mbUser.getUser().getUserID());
  }

  public String readMessage(String username, int messageId) {
    selectedMessageId = messageId;
    selectedUsername = username;
    return "readMessage";
  }

  public String delete(int messageId) {
    MessageDao.delete(messageId);
    lstMessages = MessageDao.getListMessageById(mbUser.getUser().getUserID());
    return null;
  }

}
